package com.lich.service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lich.dao.AppFunctionMapper;
import com.lich.entity.AppFunction;
import com.lich.entity.vo.Page;

@Service
public class AppFunctionService {
	@Resource
	AppFunctionMapper appFunctionMapper;
	@Resource
	ClientFunctionService clientFunctionService;
	
	/**
	 * @description 添加
	 * @date 2016年8月31日
	 * @author luosf
	 * @param product
	 * @return
	 */
	@Transactional
	public int add(AppFunction appFunction) {
		return appFunctionMapper.insert(appFunction);
	}

	/**
	 * @description 更新
	 * @date 2016年8月31日
	 * @author lich-thinkpad
	 * @param product
	 */
	public int update(AppFunction appFunction) {
		appFunctionMapper.updateById(appFunction);
		return 1;
	}
	
	/**
	 * @description 获取一页
	 * @date 2016年8月31日
	 * @author lich-thinkpad
	 * @param pageParam
	 * @return
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	public List<AppFunction> getPage(AppFunction appFunction) throws IllegalAccessException, InvocationTargetException {
		List<AppFunction> products = appFunctionMapper.selectPage(appFunction);
		return products;
	}
	
	/**
	 * @description 获取所有数据
	 * @date 2016年8月31日
	 * @author lich-thinkpad
	 * @param pageParam
	 * @return
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	public List<AppFunction> findAll() throws IllegalAccessException, InvocationTargetException {
		List<AppFunction> products = appFunctionMapper.findAll();
		
		return products;
	}
	
	/**
	 * @description 获取所有数据
	 * @date 2016年8月31日
	 * @author lich-thinkpad
	 * @param pageParam
	 * @return
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	@Transactional
	public int deleteById(Integer id) throws IllegalAccessException, InvocationTargetException {
		AppFunction appFunction = appFunctionMapper.selectById(id);
		int result = appFunctionMapper.deleteById(id);
		//逻辑删除统计数据
		result = clientFunctionService.updateDelFlagByUUID(appFunction.getUuid());
		return result;
	}
	
	/**
	 * @description 根据ID获取行
	 * @date 2016年8月31日
	 * @author lich-thinkpad
	 * @param pageParam
	 * @return
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 */
	public AppFunction selectById(Integer id) throws IllegalAccessException, InvocationTargetException {
		return appFunctionMapper.selectById(id);
	}
	
}
